import React from 'react'
import { observable, action } from "mobx";
import axios from 'axios';
import tyh from '../../component/Xf/Tyh/publicTable'
import { message } from 'antd'
const { Btn } = tyh
// -----------------------------------
const YHSH = '/wzYHSH'
const YHCOL = '/wzYHcol'
const YHDATA = '/wzYHdata'
const YHEDIT = '/wzYHedit'
const YHADD = '/wzYHadd'
// ---------------------------------
const QGSH = '/wzQGSH'
const QGCOL = '/wzQGcol'
const QGDATA = '/wzQGdata'
const QGEDIT = '/wzQGedit'
const QGADD = '/wzQGadd'
// ---------------------------------
const BTSH = '/wzBTSH'
const BTCOL = '/wzBTcol'
const BTDATA = '/wzBTdata'
const BTEDIT = '/wzBTedit'
const BTADD = '/wzBTadd'
class wzStore {
    @observable.ref columns = [];
    @observable.ref data = [];
    @observable.ref SHarr = {};
    @observable key = '1';
    @action
    getYHData = (key) => {
        console.log(key);
        axios.defaults.baseURL = '/wz'
        return axios({
            url: YHCOL,
            method: 'post'
        }).then(res => {
            this.publicMethod(res.data)
            // this.columns = res.data
            let colBox = res.data
            return axios({
                url: YHDATA,
                method: 'post',
                data: key
            }).then(res => {
                // console.log(res.data);
                this.columns = colBox
                this.data = res.data
            })
        })
    }
    @action
    getQGData = (key) => {
        axios.defaults.baseURL = '/wz'
        return axios({
            url: QGCOL,
            method: 'post'
        }).then(res => {
            this.publicMethod(res.data)
            // this.columns = res.data
            let colBox = res.data
            return axios({
                url: QGDATA,
                method: 'post',
                data: key
            }).then(res => {
                this.columns = colBox
                this.data = res.data
            })
        })
    }
    @action
    getBTData = (key) => {
        axios.defaults.baseURL = '/wz'
        return axios({
            url: BTCOL,
            method: 'post'
        }).then(res => {
            this.publicMethod(res.data)
            // this.columns = res.data
            let colBox = res.data
            return axios({
                url: BTDATA,
                method: 'post',
                data: key
            }).then(res => {
                this.columns = colBox
                this.data = res.data
            })
        })
    }

    publicMethod = (arr) => {
        arr.push({
            title: '操作',
            dataIndex: 'doit',
            align: 'center',
            render: (text, record) => (
                <Btn data={record.key} rowdata={record} />
            )
        })
        return arr
    }
    @action     //审核
    shenhe = (flag) => {
        let colURL
        let shURL
        if (this.key === '1') {
            colURL = YHCOL
            shURL = YHSH
        } else if (this.key === '2') {
            colURL = QGCOL
            shURL = QGSH
        } else if (this.key === '3') {
            colURL = BTCOL
            shURL = BTSH
        }
        // message.success('操作成功');
        if (colURL && shURL) {
            axios.defaults.baseURL = '/wz'
            return axios({
                url: colURL,
                method: 'post',
            }).then(res => {
                this.publicMethod(res.data)
                this.columns = res.data
                return axios({
                    url: shURL,
                    method: 'post',
                    data: {
                        arr: this.SHarr,
                        flag: flag
                    }
                }).then(res => {
                    // console.log(res.data);
                    this.data = res.data
                })
            })
        } else {
            message.info('请正确操作')
        }

    }
    @action     //编辑
    editAxios = (obj) => {
        // console.log(this.key);
        // console.log(obj);
        let URL
        if (this.key === '1') {
            URL = YHEDIT
        } else if (this.key === '2') {
            URL = QGEDIT
        } else if (this.key === '3') {
            URL = BTEDIT
        }
        axios.defaults.baseURL = '/wz'
        return axios({
            url: URL,
            method: 'post',
            data: obj
        }).then(res => {
            console.log(res);
            this.data = res.data
        })
    }
    @action     //添加
    addNew = (obj) => {
        obj.key = this.data.length + 1 + ''
        // console.log(obj);
        let URL
        if (this.key === '1') {
            URL = YHADD
        } else if (this.key === '2') {
            URL = QGADD
        } else if (this.key === '3') {
            URL = BTADD
        }
        axios.defaults.baseURL = '/wz'
        return axios({
            url: URL,
            method: 'post',
            data: obj
        }).then(res => {
            console.log(res);
            this.data = res.data
        })
    }
}

export default wzStore;
